package com.ln.lnzw.activity;

import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.blankj.utilcode.util.RegexUtils;
import com.ln.lnzw.R;
import com.ln.lnzw.base.BaseActivity;
import com.ln.lnzw.utils.CacheActivity;
import com.ln.lnzw.utils.ToastFactory;
import com.ln.lnzw.view.ClearableEditText;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by wuwei on 2018/4/8.
 * 实名认证
 */

public class VerifiedActivity extends BaseActivity {
    @BindView(R.id.iv_back)
    ImageView ivBack;
    @BindView(R.id.tv_jump_over)
    TextView tvJumpOver;
    @BindView(R.id.cet_name)
    ClearableEditText cetName;
    @BindView(R.id.cet_zhengjianhaoma)
    ClearableEditText cetZhengjianhaoma;
    @BindView(R.id.rl_queding)
    RelativeLayout rlQueding;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_verified);
        ButterKnife.bind(this);
        CacheActivity.addActivity(VerifiedActivity.this);

        setView();
    }

    private void setView() {
        cetName.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void afterTextChanged(Editable editable) {
                editTextIsYesAndNo();
            }
        });
        cetZhengjianhaoma.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void afterTextChanged(Editable editable) {
                editTextIsYesAndNo();
            }
        });

    }
    private void editTextIsYesAndNo() {
        if (!TextUtils.isEmpty(cetName.getText())&&!TextUtils.isEmpty(cetZhengjianhaoma.getText())){
            rlQueding.setBackground(getResources().getDrawable(R.drawable.button_bg_yes));
        }
        if (TextUtils.isEmpty(cetName.getText())||TextUtils.isEmpty(cetZhengjianhaoma.getText())){
            rlQueding.setBackground(getResources().getDrawable(R.drawable.button_bg_no));
        }
    }
    @OnClick({R.id.iv_back, R.id.tv_jump_over,R.id.rl_queding})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_back:
                finish();
                break;
            case R.id.tv_jump_over:
//                finish();
                CacheActivity.finishActivity();
                break;
            case R.id.rl_queding:
                 if (!RegexUtils.isIDCard18(cetZhengjianhaoma.getText())){
                     ToastFactory.getToast(activity,"身份证格式不正确").show();
                     return;
                 }
                CacheActivity.finishActivity();
                 //请求接口
                break;
        }
    }


}
